import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    BindAccountViewState state, Dispatch dispatch, ViewService viewService) {
  return Scaffold(
    appBar: myAppBar(viewService.context, title: '绑定户号', actions: [
      GestureDetector(
        behavior: HitTestBehavior.translucent,
        child: Container(
          padding: EdgeInsets.only(right: 12),
          height: 40,
          child: Center(
            child: Text(
              '查询',
              style: TextThemeConfig.ActionBarTitle,
            ),
          ),
        ),
        onTap: () async {
          var res = await CommonUtils.pushRoute(
              viewService.context, RoutePath.searchAccountView);
          if (res == '成功') {
            Navigator.pop(viewService.context);
          }
        },
      ),
    ]),
    resizeToAvoidBottomPadding: false,
    backgroundColor: Colors.white,
    body: GestureDetector(
      behavior: HitTestBehavior.translucent,
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(left: 45, right: 45, top: 40),
            decoration: BoxDecoration(
              border: Border.all(color: Color(0xffEAEAEA), width: 0.5),
              borderRadius: BorderRadius.all(Radius.circular(4)),
              color: ThemeConfig.separeColor,
            ),
            height: 50,
            child: Row(
              children: [
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 14),
                  child: Image.asset('images/ic_account.png'),
                ),
                Container(
                  height: 24,
                  width: 0.5,
                  color: Color(0xffc1c1c1),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.only(left: 14),
                    child: TextField(
                      style: TextStyle(
                          fontSize: 14, color: ThemeConfig.blackColor),
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: "请输入您的户号",
                        hintStyle: TextStyle(fontSize: 14),
                        contentPadding: EdgeInsets.only(),
                      ),
                      controller: state.accountController,
//                onChanged: (String str) {
//                  if (str.length > ThemeConfig.passwordTextLength)
//                    state.passwordController.text = str.substring(
//                        0, ThemeConfig.passwordTextLength);
//                },
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 45, right: 45, top: 20),
            decoration: BoxDecoration(
              border: Border.all(color: Color(0xffEAEAEA), width: 0.5),
              borderRadius: BorderRadius.all(Radius.circular(4)),
              color: ThemeConfig.separeColor,
            ),
            height: 50,
            child: Row(
              children: [
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 14),
                  child: Image.asset('images/ic_psword.png'),
                ),
                Container(
                  height: 24,
                  width: 0.5,
                  color: Color(0xffc1c1c1),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.only(left: 14),
                    child: TextField(
                      style: TextStyle(
                          fontSize: 14, color: ThemeConfig.blackColor),
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: "请输入户主姓名",
                        hintStyle: TextStyle(fontSize: 14),
                        contentPadding: EdgeInsets.only(),
                      ),
                      controller: state.nameController,
//                onChanged: (String str) {
//                  if (str.length > ThemeConfig.passwordTextLength)
//                    state.passwordController.text = str.substring(
//                        0, ThemeConfig.passwordTextLength);
//                },
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 45, right: 45, top: 40),
            height: 50,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(4)),
              color: ThemeConfig.mainColor,
            ),
            child: InkWell(
              child: Center(
                child: Text(
                  '立即绑定',
                  style: TextThemeConfig.Font16WithWhite,
                ),
              ),
              onTap: () => dispatch(BindAccountViewActionCreator.onSubmit()),
            ),
          ),
        ],
      ),
      onTap: () => FocusScope.of(viewService.context).requestFocus(FocusNode()),
    ),
  );
}
